﻿using IBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace ZG2RK11API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RKController : ControllerBase
    {
        IWebHostEnvironment Web;
        public RKController(IRKBLL bll, IWebHostEnvironment Web)
        {
            Bll = bll;
            this.Web = Web;
        }

        public IRKBLL Bll { get; }
        [HttpPost]
        public Task<int> Add(YHmdel y)
        {
            return Bll.Add(y);
        }
        [HttpGet]
        public Task<int> Delete(int id)
        {
          return Bll.Delete(id);
        }
        [HttpGet]
        public dynamic Show()
        {
           return Bll.Show();
        }
        [HttpPost]
        public Task<int> Update(YHmdel y)
        {
            return Bll.Update(y);
        }
        [HttpPost]
        public IActionResult shangchuan(IFormFile file)
        {
            string a = Guid.NewGuid().ToString(); 
            string b = Web.WebRootPath + @"\img\" + a + file.FileName;

            using (FileStream c = System.IO.File.Create(b))
            {
                file.CopyTo(c);
                c.Close();
            }
            return Ok("/img/" + a + file.FileName);
        }
    }
}
